package com.sqfw.project.wp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sqfw.framework.aspectj.lang.annotation.Log;
import com.sqfw.framework.aspectj.lang.enums.BusinessType;
import com.sqfw.project.wp.domain.WpHandleLog;
import com.sqfw.project.wp.service.IWpHandleLogService;
import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.framework.web.domain.AjaxResult;
import com.sqfw.common.utils.poi.ExcelUtil;
import com.sqfw.framework.web.page.TableDataInfo;

/**
 * 工单主轨迹表Controller
 * 
 * @author lx
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/wp/wp_handle_log")
public class WpHandleLogController extends BaseController
{
    @Autowired
    private IWpHandleLogService wpHandleLogService;

    /**
     * 查询工单主轨迹表列表
     */
    @PreAuthorize("@ss.hasPermi('wp:wp_handle_log:list')")
    @GetMapping("/list")
    public TableDataInfo list(WpHandleLog wpHandleLog)
    {
        startPage();
        List<WpHandleLog> list = wpHandleLogService.selectWpHandleLogList(wpHandleLog);
        return getDataTable(list);
    }

    /**
     * 导出工单主轨迹表列表
     */
    @PreAuthorize("@ss.hasPermi('wp:wp_handle_log:export')")
    @Log(title = "工单主轨迹表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WpHandleLog wpHandleLog)
    {
        List<WpHandleLog> list = wpHandleLogService.selectWpHandleLogList(wpHandleLog);
        ExcelUtil<WpHandleLog> util = new ExcelUtil<WpHandleLog>(WpHandleLog.class);
        util.exportExcel(response, list, "工单主轨迹表数据");
    }

    /**
     * 新增工单主轨迹表
     */
    @PreAuthorize("@ss.hasPermi('wp:wp_handle_log:add')")
    @Log(title = "工单主轨迹表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WpHandleLog wpHandleLog)
    {
        return toAjax(wpHandleLogService.insertWpHandleLog(wpHandleLog));
    }

    /**
     * 修改工单主轨迹表
     */
    @PreAuthorize("@ss.hasPermi('wp:wp_handle_log:edit')")
    @Log(title = "工单主轨迹表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WpHandleLog wpHandleLog)
    {
        return toAjax(wpHandleLogService.updateWpHandleLog(wpHandleLog));
    }

    /**
     * 删除工单主轨迹表
     */
    @PreAuthorize("@ss.hasPermi('wp:wp_handle_log:remove')")
    @Log(title = "工单主轨迹表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wpids}")
    public AjaxResult remove(@PathVariable String[] wpids)
    {
        return toAjax(wpHandleLogService.deleteWpHandleLogByWpids(wpids));
    }

    /**
     * 根据工单编号，查询轨迹详细信息
     * @param processId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('getWpHandleDetailed')")
    @GetMapping("/getWpHandleDetailed")
    public AjaxResult getWpHandleDetailed(String processId){

        WpHandleLog wpHandleLog = wpHandleLogService.getWpHandleDetailedById(processId);

        return AjaxResult.success(wpHandleLog);

    }
}
